<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>java代码热部署</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<div class="layui-form-item"></div>
<div style="text-align: center;">
    <form class="layui-form" action="" style="margin:10px auto;width:600px">
        <div class="layui-form-item layui-inline">
            <div>注意事项：类热部署替换不一定100%成功，请在熟知原理的情况下操作</div>
        </div>
        <div class="layui-form-item">
           <label class="layui-form-label">应用名称</label>
               <select id="appName" style="display:block;">
                   <option value="fms">FMS</option>
                   <option value="thirdpart">第三方接口</option>
               </select>
        </div>
        <div class="layui-form-item">
            <input type="text" id="fullClassName" required placeholder="类全路径名称, 比如com.eptison.eop.xxxBizServiceImpl" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-item">
            <button type="button" class="layui-btn" id="test1">
              <i class="layui-icon">&#xe67c;</i>上传.class文件
            </button>
        </div>
        <div class="layui-form-item">
            <button type="button" class="layui-btn layui-btn-danger" onclick="doSubmit()">提交</button>
            <button type="reset" class="layui-btn layui-btn-normal">重置</button>
        </div>
    </form>
</div>


<script src="../layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    var tableRender = null;
    var layer = null;
    var uploadInst = null;
    layui.use(['jquery', 'upload', 'layer'], function(){
        var form = layui.form;
        layer = layui.layer;
        var jQuery = layui.$ //重点处


        var upload = layui.upload;
        var fullClassName = null;
        //执行实例
        uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,auto: false //选择文件后不自动上传
            ,exts: 'class' //只能允许class文件上传
            ,url: './uploadAndSendBusMsg?xAuthToken=${xAuthToken}' //上传接口
            ,data: {
                fullClassName: function(){return jQuery("#fullClassName").val();},
                appName: function(){return jQuery("#appName").val();}
            } //其他json数据
            ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.load(); //上传loading
            }
            ,done: function(res){
              //上传完毕回调
              layer.closeAll('loading'); //关闭loading
              if(res.code != 0){
                 layer.msg(res.msg);
              }else{
                 layer.msg("热替换消息发送成功, 替换结果请等待钉钉消息通知");
              }
            }
            ,error: function(){
              layer.msg("网络请求异常");
              //请求异常回调
              layer.closeAll('loading'); //关闭loading
            }
        });
    });

    function doSubmit(){
        layer.open({
          content: '确认热部署？请谨慎操作',
          yes: function(index, layero){
            uploadInst.upload();
            layer.close(index);
          },
          cancel: function(index, layero){
            layer.close(index);
          }
        });
    }

</script>

</body>
</html>